package cn.sdormitory.login;

import cn.sdormitory.basedata.entity.BStudent;
import cn.sdormitory.sys.enums.StatusEnums;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @author: lx
 * @date: 2023/11/8 14:05
 * @description:
 */
public class BStudentDetails implements UserDetails {

    private static final long serialVersionUID = 8605341996226864831L;

    private BStudent bStudent;

    public BStudentDetails(BStudent bStudent) {
        this.bStudent = bStudent;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        //返回当前用户的权限
        return null;
    }


    @Override
    public String getPassword() {
        return bStudent.getStudentPassword();
    }

    @Override
    public String getUsername() {
        return bStudent.getPhone();
    }

    /**
     * 账户是否未过期,过期无法验证
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 指定用户是否解锁,锁定的用户无法进行身份验证
     *
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
     *
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 是否可用 ,禁用的用户不能身份验证
     *
     * @return
     */
    @Override
    public boolean isEnabled() {
        return StatusEnums.ENABLE.getKey().equals(bStudent.getStatus());
    }

    public BStudent getSysUser() {
        return this.bStudent;
    }

    public void setSysUser(BStudent sysUser) {
        this.bStudent = sysUser;
    }
}
